<template>
  <span>三方登录中...</span>
</template>

<script setup lang="ts">
import { useRoute } from 'vue-router'
import { useLoginUserStore } from '@/stores/counter'
import { onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
import router from '@/router'

const isBind = ref<boolean>(false)
const route = useRoute()
const loginUserStore = useLoginUserStore()
const login = async () => {
  // 登录成功，把登录态保存到全局状态中
  const res = route.query.isBind
  const UUID = route.query.UUID
  const source = route.query.source
  console.log('res = ' + res)
  if (res && res === 'true') {
    isBind.value = true
    await loginUserStore.fetchLoginUser()
    message.success('登录成功')
    router.push({
      path: '/',
      replace: true,
    })
  } else {
    isBind.value = false
    localStorage.setItem('isBind', 'false')
    localStorage.setItem('UUID', UUID as string)
    localStorage.setItem('source', source as string)
    message.error('该三方账号未绑定用户，请绑定')
    router.push({
      path: '/user/login',
      replace: true,
    })
  }
}

onMounted(() => {
  login()
})
</script>

<style scoped></style>
